package com.zhangsun.consumer;

import com.zhangsun.common.RabbitMqDirectConstant;
import com.zhangsun.system.entity.UserEntity;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.messaging.handler.annotation.Payload;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * Direct模式消费者
 */
@Component
public class HelloConsumer {

    /**
     * 执行消息
     *
     * @param user 参数
     */
    @RabbitListener(queues = RabbitMqDirectConstant.QUEUE_HELLO)
    public void process(@Payload UserEntity user) {
        System.out.println(new Date());
        try {
            Thread.currentThread().sleep(5000);
        } catch (InterruptedException ie) {
            ie.printStackTrace();
        }
        System.out.println(new Date());
        System.out.println(RabbitMqDirectConstant.QUEUE_HELLO + "：" + user.toString());
    }

}
